home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
comm2
/
mfstlntd.lha
/
telnetd2_0.lha
/
telnetd-2.0
/
source
/
RCS
/
TnServ.c
< prev
Wrap
C/C++ Source or Header
|
1995-04-13
|
9KB
|
357 lines
head 2.0;
access;
symbols;
locks; strict;
comment @ * @;
2.0
date 95.04.13.19.53.48; author simons; state Exp;
branches;
next 1.5;
1.5
date 95.01.24.02.42.20; author simons; state Exp;
branches;
next 1.4;
1.4
date 95.01.22.19.37.23; author simons; state Exp;
branches;
next 1.3;
1.3
date 95.01.22.19.30.16; author simons; state Exp;
branches;
next 1.2;
1.2
date 95.01.22.18.48.36; author simons; state Exp;
branches;
next 1.1;
1.1
date 95.01.22.18.07.20; author simons; state Exp;
branches;
next ;
desc
@TnServ sits in the background and fetches incoming telnet
connects, handing them over to TelnetGetty.
@
2.0
log
@Updated my e-mail address to .rhein.de.
@
text
@/*
* $Filename: TnServ.c $
* $Revision: 1.5 $
* $Date: 1995/01/24 02:42:20 $
*
* Copyright (C) 1993,94 by Steve Holland <sdh4@@cornell.edu>
* Copyright (C) 1995 by Peter Simons <simons@@peti.rhein.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: TnServ.c 1.5 1995/01/24 02:42:20 simons Exp simons $
*
*/
/************************************* includes ***********/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <proto/socket.h>
#include <netdb.h>
#include <errno.h>
#include <dos/dos.h>
#include <dos/dostags.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <clib/netlib_protos.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "TnServ_rev.h"
/************************************* defines ************/
/************************************* global variables ***/
static const char __DOSVer[] = VERSTAG " written by Peter Simons <simons@@peti.rhein.de>";
int main(void)
{
struct servent *sp;
struct sockaddr_in ServAddr;
LONG Socket, SubSock, SubSockID;
int WaitSig;
static char ArgStr[200];
BPTR TelNetProg;
long Len;
if (!(sp = getservbyname("telnet", "tcp")))
return 21;
bzero(&ServAddr, sizeof(ServAddr));
ServAddr.sin_port = sp->s_port;
ServAddr.sin_addr.s_addr = htonl(INADDR_ANY);
ServAddr.sin_family = AF_INET;
ServAddr.sin_len = sizeof(ServAddr);
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket < 0)
return 22;
bind(Socket, (struct sockaddr *) &ServAddr, sizeof(ServAddr));
listen(Socket, 5);
WaitSig = AllocSignal(-1);
if (WaitSig == -1)
return 23;
for (;;) {
Len = sizeof(ServAddr);
SubSock = accept(Socket, (struct sockaddr *) &ServAddr, &Len);
if (SubSock < 0) {
if (Errno() == EINTR) {
CloseSocket(Socket);
return 0;
}
continue;
}
SetSignal(0, (1 << WaitSig)); /* unset WaitSig signal */
SubSockID = ReleaseSocket(SubSock, UNIQUE_ID);
sprintf(ArgStr, "%u %u %u", (unsigned long) SubSockID, (unsigned long) WaitSig, (unsigned long) FindTask(NULL));
if (TelNetProg = LoadSeg("AmiTCP:serv/telnetd")) {
if (CreateNewProcTags(NP_Seglist, TelNetProg,
NP_Name, "telnet login",
NP_Arguments, ArgStr,
NP_StackSize, 12000,
NP_FreeSeglist, TRUE,
TAG_END)) {
/* CreateProc("telnet login",0,TelNetProg,12000); */
Wait(1 << WaitSig); /* Wait for new proc to start up */
}
}
}
}
/************************************* subroutines ********/
@
1.5
log
@TnServ expects the daemon now as AmiTCP:serv/telnetd. The tnserv:-
assign is history.
@
text
@d3 2
a4 2
* $Revision: 1.4 $
* $Date: 1995/01/22 19:37:23 $
d7 1
a7 1
* Copyright (C) 1995 by Peter Simons <simons@@peti.GUN.de>
d23 1
a23 1
* $Id: TnServ.c 1.4 1995/01/22 19:37:23 simons Exp simons $
d49 1
a49 1
static const char __DOSVer[] = VERSTAG " written by Peter Simons <simons@@peti.GUN.de>";
@
1.4
log
@Now using the autoinit functions in net.lib, rather than installing
an atexit() hook myself.
@
text
@d3 2
a4 2
* $Revision: 1.3 $
* $Date: 1995/01/22 19:30:16 $
d23 1
a23 1
* $Id: TnServ.c 1.3 1995/01/22 19:30:16 simons Exp simons $
d91 1
a91 8
TelNetProg = LoadSeg("tnserv:TelnetGetty");
if (!TelNetProg)
TelNetProg = LoadSeg("TelnetGetty/TelnetGetty");
if (!TelNetProg)
TelNetProg = LoadSeg("TelnetGetty");
if (!TelNetProg)
TelNetProg = LoadSeg("AmiTCP:Bin/TelnetGetty");
if (TelNetProg) {
@
1.3
log
@Added version string and "written by"-line with my name.
@
text
@d3 2
a4 2
* $Revision: 1.2 $
* $Date: 1995/01/22 18:48:36 $
d23 1
a23 1
* $Id: TnServ.c 1.2 1995/01/22 18:48:36 simons Exp simons $
d38 1
a46 1
void FreeResources(void);
a49 1
struct Library *SocketBase = NULL;
a60 6
if (atexit(FreeResources))
return 20;
if (!(SocketBase = OpenLibrary("bsdsocket.library", 2)))
return 20;
a115 7
void FreeResources(void)
{
if (SocketBase)
CloseLibrary(SocketBase);
}
@
1.2
log
@Changed source to compile under SAS/C 6.51.
Added GNU GPL header and my copyright.
Reformatted source with indent.
Added atexit() hook to close the library when exiting.
@
text
@d3 2
a4 2
* $Revision$
* $Date$
d23 1
a23 1
* $Id$
d49 1
a49 1
static const char __DOSVer[] = VERSTAG;
@
1.1
log
@Initial revision
@
text
@d1 27
d38 1
d43 8
a50 3
struct Library *SocketBase=NULL;
#define bzero(base,n) memset(base,0,n)
#define bcopy(from,to,n) memcpy(to,from,n)
d52 1
a52 1
void Quit(int retcode)
d54 65
a118 3
if (SocketBase) CloseLibrary(SocketBase);
exit(retcode);
d121 3
a123 1
struct Process *MyCreateNewProcTags(ULONG Tag0,...)
d125 2
a126 1
return CreateNewProc((struct TagItem *)&Tag0);
d129 1
a129 63
void main(void)
{
struct servent *sp;
struct sockaddr_in ServAddr;
int Socket,SubSock;
LONG SubSockID;
int WaitSig;
static char ArgStr[200];
BPTR TelNetProg;
long Len;
SocketBase=OpenLibrary("bsdsocket.library",2);
if (!SocketBase) Quit(20);
sp=getservbyname("telnet","tcp");
if (!sp) Quit(21);
bzero(&ServAddr,sizeof(ServAddr));
ServAddr.sin_port=sp->s_port;
ServAddr.sin_addr.s_addr=htonl(INADDR_ANY);
ServAddr.sin_family=AF_INET;
ServAddr.sin_len=sizeof(ServAddr);
Socket=socket(AF_INET,SOCK_STREAM,0);
if (Socket < 0) Quit(22);
bind(Socket,&ServAddr,sizeof(ServAddr));
listen(Socket,5);
WaitSig=AllocSignal(-1);
if (WaitSig==-1) Quit(23);
for (;;) {
Len=sizeof(ServAddr);
SubSock=accept(Socket,&ServAddr,&Len);
if (SubSock < 0) {
if (Errno()==EINTR) {
CloseSocket(Socket);
Quit(0);
}
continue;
}
SetSignal(0,(1<<WaitSig)); /* unset WaitSig signal */
SubSockID=ReleaseSocket(SubSock,UNIQUE_ID);
sprintf(ArgStr,"%u %u %u",(unsigned long)SubSockID,(unsigned long)WaitSig,(unsigned long)FindTask(NULL));
TelNetProg=LoadSeg("tnserv:TelnetGetty");
if (!TelNetProg) TelNetProg=LoadSeg("TelnetGetty/TelnetGetty");
if (!TelNetProg) TelNetProg=LoadSeg("TelnetGetty");
if (!TelNetProg) TelNetProg=LoadSeg("AmiTCP:Bin/TelnetGetty");
if (TelNetProg) {
if (MyCreateNewProcTags(NP_Seglist,TelNetProg,
NP_Name,"telnet login",
NP_Arguments,ArgStr,
NP_StackSize,12000,
NP_FreeSeglist,TRUE,
TAG_END)) {
/*CreateProc("telnet login",0,TelNetProg,12000);*/
Wait(1<<WaitSig); /* Wait for new proc to start up */
}
}
}
}
@